package com.dhcc.sds.standard.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcOrdmastEntity;
import com.dhcc.cdc.sys.entity.DictionaryEntity;
import com.dhcc.cdc.sys.service.IDictionaryService;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.sds.base.entity.SdsDicEntity;
import com.dhcc.sds.base.service.ISdsDicService;
import com.dhcc.sds.standard.dto.CdcOrdmastDto;
import com.dhcc.sds.standard.entity.SdsStandOrderMatchEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 数据中心字典对照单病种字典
 *
 * @ClassName: SdsStandCdcMatchController
 * @Description: TODO
 * @author zhangdc
 * @date 2021-06-09 10:09:56
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsstandcdcmatch")
public class SdsStandCdcMatchController {

    private String PREFIX = "/backend/sds/sdsstandcdcmatch/";

    @Autowired
    private IDictionaryService dictionaryService;

    /**
     * 跳转到数据中心字典对照列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdsstandcdcmatch.html";
    }

    /**
     * 获取数据中心字典对照列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
        Page<DictionaryEntity> page = new PageFactory<DictionaryEntity>().defaultPage();
        List<DictionaryEntity> result = this.dictionaryService.pageByProductCodeAndTypeCode(page,params,"SDS","SDMatchCdcDic");
        page.setRecords((List<DictionaryEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 数据中心字典对照
     */
    @RequestMapping(value = "/compare")
    @ResponseBody
    public Object compare(@RequestParam Long cdcSysDicId, @RequestParam Long cdcCtDicId) {
        this.dictionaryService.compare(cdcSysDicId, cdcCtDicId);
        return R.ok();
    }

    /**
     * 撤销数据中心字典对照
     */
    @RequestMapping(value = "/undo")
    @ResponseBody
    public Object undo(@RequestParam Long cdcSysDicId, @RequestParam Long cdcCtDicId) {
        this.dictionaryService.undo(cdcSysDicId, cdcCtDicId);
        return R.ok();
    }

    /**
     * 对照的标准字典进行渲染
     */
    @RequestMapping(value = "/matchDicsub")
    @ResponseBody
    public Object matchDicsub() {

        List<Long> matchIds = this.dictionaryService.selectMatchDicsub();

        return matchIds;
    }


}
